package com.example.demo.web.rx.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Mapping;
import reactor.core.publisher.Mono;

/**
 * @author airhead
 */
@Controller
@Mapping("/rx")
@Api("响应式服务")
public class RxController {
  @Mapping("/hello")
  @ApiOperation("hello")
  public Mono<String> hello(String name) {
    return Mono.just("Hello " + name);
  }

  @Mapping("/helloWithError")
  @ApiOperation("helloWithError")
  public Mono<String> helloWithError() {
    return Mono.create(call -> call.error(new IllegalStateException("test")));
  }

  @Mapping("/helloRetVoid")
  @ApiOperation("helloRetVoid")
  public Mono<Void> helloRetVoid() {
    return Mono.empty();
  }

  @Mapping("/helloBySupplier")
  @ApiOperation("helloBySupplier")
  public Mono<String> helloBySupplier(String name) {
    return Mono.fromSupplier(() -> "Hello " + name);
  }
}
